/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#pragma once
#include <string>
#include <map>

#include "IEntity.h"
#include "Event.h"

#include "../render/IView2D.h"
#include "../render/Image.h"
#include "../render/IRender.h"
#include "../render/Animation.h"
#include "../shared/geom.h"

/**
=================================
A tile on the map
=================================
*/
class Tile : public IView2D
{
public:
    Tile();
    Tile(Image im, int fps, int amountOfFrames, int r, int c) : m_row(r), m_col(c)
    {   m_image = im;
        m_animation.Set(fps, m_row, m_col, amountOfFrames); 
    };
	/** Initialize the Tile */
    int Init( Image image);
	/** Update the animation */
    void Update(long dt);
	/** Render the tile */
    void Render( IRender *r, ICamera* cam );

	/** Set the location of the tile */
    void Set(int x, int y){ m_x = x; m_y = y; };
    
	/** Set the Event that is associated with this tile 
     *  Note there is only ONE tile ref, so we have a 
     *  list of Events with a tile at a point.  So when
     *  a tile is drawn at a point, we don't need multiple 
     *  tiles and waste memory.
     */
	void AddEvent( const Vector2f &v, TileEvent &evnt );

	/** Trigger the event */
	void Trigger( IEntity* triggerer, const Vector2f &v );

    /** Get the bounds */
    Rect GetBounds() { return Rect( m_x, m_y, m_width, m_height ); };

    virtual ~Tile();
    	// the image for this time
    Image       m_image;
private:
    Animation   m_animation;
    // row and column for the image
    int m_row;
    int m_col;

    // events for each tile of this type
    /** NOTE: Must make it std::pair because gives me weird compile errors
        when using MPoint
     */
    typedef std::map< std::pair<int, int>, TileEvent > type_Events;
    type_Events m_events;


public:
    int                     m_x;
    int                     m_y;
    int                     m_width;
    int                     m_height;
};
